// import axios from 'axios'
import React from 'react'
import {connect} from 'react-redux'
import withRouter from '../withRouter'
import { Result, List, WhiteSpace, Modal } from 'antd-mobile'
import browserCookie from 'browser-cookies'
import {logoutSubmit} from '../../redux/user.redux'
// import { Navigate } from 'react-router-dom'
@withRouter
@connect(
    state=>state.user,
    {logoutSubmit}
)
class User extends React.Component {
    // constructor(props) {
    //     super(props)
    //     this.logout = this.logout.bind(this)
    //     this.state = {
    //         data: []
    //     }
    // }
    logout() {
        const alert = Modal.alert
        alert('注销', '确认退出???', [
              { text: '取消', onPress: () => console.log('取消') },
              { text: '确认', onPress: () => {
                browserCookie.erase('userid')
                this.props.logoutSubmit()
                // console.log(this.props)
                // this.props.navigate('/login')
                // window.location.href = window.location.href
              } },
            ])
    }
    // componentDidUpdate() {
    //     axios.get('/user/list?type=genius').then(res => {
    //         if(res.data.code === 0) {
    //             this.setState({data: res.data.data})
    //         }
    //     })
    // }
    render(h) {
        const props = this.props
        const Item = List.Item
        const Brief = Item.Brief
        // console.log('props.user:', props.user, ',', props.redirectTo)
        !props.user && props.navigate('/login')
        return props.user?(
            <div>
                <Result 
                    img={<img src={require(`../img/${this.props.avatar}.png`)} style={{width:50}} alt="" />}
                    title={this.props.user}
                    message={props.type==='boss'?props.company:null}
                />
                <List renderHeader={()=>'简介'}>
                    <Item
                        multipleLine
                    >
                        {props.title}
                        {props.desc.split('\n').map(v=><Brief key={v}>{v}</Brief>)}
                        {props.money?<Brief>薪资：{props.money}</Brief>:null}
                    </Item>
                </List>
                <WhiteSpace></WhiteSpace>
                <List>
                    <Item onClick={v=>this.logout()}>退出登录</Item>
                </List>
            </div>
        // ):<Navigate to={props.redirectTo} />
        ):null
    }
}

export default User